<?php
/**
 * Created by PhpStorm.
 * User: jiangtaiping
 * Date: 2017/2/23
 * Time: 14:19
 */
class Controller_Admin_Public
{
    /**
     * 显示用户登录的验证码
     */
    public function authCodeAction()
    {
        Service_Public::authCode();
    }

    public function getCityAction(){
        $provinceCode = FRequest::getString("pro_code") ? FRequest::getString("pro_code") : "";
        if($provinceCode){
            $list = Service_User::getCity($provinceCode);
            if($list){
                $result = array('status' => 200, "data" => $list);
            }else{
                $result = array("status" => -1 , "error" => "城市数据未查询到");
            }
        }else{
            $result = array("status" => -2 , "error" => "省份id为空");
        }
        FResponse::output($result);
    }

    /*
     * 小红薯订单提交
     * nickname:nickname,
                    mobile:mobile,
                    intention:intention,
                    province:pro,
                    city:city
     */
    public function userOrderDealAction(){
        $nickname = FRequest::getPostString("nickname") ? FRequest::getPostString("nickname") : "";
        $mobile = FRequest::getPostString("mobile") ? FRequest::getPostString("mobile") : "";
        $intention = FRequest::getPostInt("intention") ? FRequest::getPostInt("intention") : 1;
        $province = FRequest::getPostString("province") ? FRequest::getPostString("province") : "";
        $city = FRequest::getPostString("city") ? FRequest::getPostString("city") : "";
        $source = FRequest::getPostString("domain") ? FRequest::getPostString("domain") : "";
        $data = array(
            "nickname" => $nickname,
            "mobile" => $mobile,
            "join_intention" => $intention,
            "province" => $province,
            "city" => $city,
            "source" => $source,
            "status" => 1,
        );

//        FResponse::output($data);

        $table = new FTable('user_order', "", "");
        $ret = $table->insert($data);
        if($ret){
            $result = array('status' => 200, 'data' => '提交成功！');
        }else{
            $result = array('status' => -2, 'error' => '提交失败！');
        }
        FResponse::output($result);
    }

    /*
     * 获取省份信息
     */
    public function getProAction(){
        $data = Service_User::getProvince();
        if(!$data){
            $result = array("status" => -2 , "error" => "省份数据未查询到");
        }else{
            $result = array("status" => 200 , "data" => $data);
        }
        FResponse::output($result);
    }


}